package com.lyz.dataStructure.algorithm.sanliuling2020;/**
 * @Author:759057893@qq.com Lyz
 * @Date: ${Date} 20:55
 * @Description:
 **/

import java.util.Scanner;

/**
 *@Author:759057893@qq.com Lyz
 *@Date: 2019/8/15 20:55
 *@Description:
 **/
public class Main1 {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        int[][] arr = new int[n][m];
        int num = 0;
        int fg=0;
        for(int i=0;i<n;i++){
            for(int j=0;j<n;j++){
                arr[i][j] = sc.nextInt();
                if(arr[i][j]>1){
                    fg +=arr[i][j]-1;
                }
                num+=arr[i][j];
            }
        }
        int sumA = num*6-fg*2;
        for(int i=0;i<n-1;i++){
            for(int j=0;j<n-1;j++){
                if(arr[i][j+1]!=0){
                    sumA-=2;
                }
                if(arr[i+1][j]!=0){
                    sumA-=2;
                }

            }
        }
        if(arr[n-1][n-1-1]!=0){
            sumA-=2;
        }
        if(arr[n-1-1][n-1]!=0){
            sumA-=2;
        }
        System.out.println(sumA);
    }
}
